package com.weilan.ark3.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.weilan.ark3.buffer.MsgQueue;
import com.weilan.ark3.buffer.OverallSituation;
import com.weilan.ark3.entity.ControlRtu;

import com.weilan.ark3.mapper.ControlRtuMapper;
import com.weilan.ark3.service.ControlRtuService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 */
@Service
public class ControlRtuServiceImpl extends ServiceImpl<ControlRtuMapper, ControlRtu> implements ControlRtuService {

    @Override
    public void readModBusRTUData(String comName) {
        LambdaQueryWrapper<ControlRtu> wrapper = new LambdaQueryWrapper<ControlRtu>().eq(ControlRtu::getIsRead, 1).eq(ControlRtu::getComName, comName).eq(ControlRtu::getRank, 1);
        OverallSituation.com1MessgeRank1 = this.list(wrapper);
    }

    @Override
    public void readModBusRTUData2(String com1) {
        LambdaQueryWrapper<ControlRtu> wrapper = new LambdaQueryWrapper<ControlRtu>().eq(ControlRtu::getIsRead, 1).eq(ControlRtu::getComName, com1).eq(ControlRtu::getRank, 2);
        OverallSituation.com1MessgeRank2 = this.list(wrapper);
    }

    @Override
    public void readModBusRTUDataPV(String com2) {
        LambdaQueryWrapper<ControlRtu> wrapper = new LambdaQueryWrapper<ControlRtu>().eq(ControlRtu::getIsRead, 1).eq(ControlRtu::getComName, com2).eq(ControlRtu::getRank, 1);
        List<ControlRtu> rtuList = this.list(wrapper);
        rtuList.forEach(e -> {
            MsgQueue.writeToQueue(e);
        });
    }


    @Override
    public void readModBusRTUDataCOM2(String com2) {
        LambdaQueryWrapper<ControlRtu> wrapper = new LambdaQueryWrapper<ControlRtu>().eq(ControlRtu::getIsRead, 1).eq(ControlRtu::getComName, com2).eq(ControlRtu::getRank, 1);
        List<ControlRtu> rtuList = this.list(wrapper);
        rtuList.forEach(e -> {
            MsgQueue.writeToQueue(e);
        });
    }

    @Override
    public void readModBusTCPData(String tcp) {
        LambdaQueryWrapper<ControlRtu> wrapper = new LambdaQueryWrapper<ControlRtu>()
                .eq(ControlRtu::getIsRead, 1)
                .eq(ControlRtu::getComName, tcp)
                .eq(ControlRtu::getRank, 1);
        OverallSituation.tcpMessgeRank1 = this.list(wrapper);
    }

    @Override
    public void readModBusTCP2Data(String tcp) {
        LambdaQueryWrapper<ControlRtu> wrapper = new LambdaQueryWrapper<ControlRtu>()
                .eq(ControlRtu::getIsRead, 1)
                .eq(ControlRtu::getComName, tcp)
                .eq(ControlRtu::getRank, 2);
        OverallSituation.tcpMessgeRank2 = this.list(wrapper);
    }
}
